<?php
defined('SEJUJOPEFDNGJSL') or exit('Access denied');

$pagecount=getnums($_GET["pagecount"],$GLOBALARR['pagecount']);
$orderby=getnums($_GET['orderby'],1);
$quser=checkstr(trim($_REQUEST['quser']));
$wherep=checkstr($_GET['wherep']);
$tmp_arr['torderby']='<a href="'.getqueurl('orderby',geteqval(array($orderby,1,'2','1'))).'" class="'.((strstr($orderby,'1')||strstr($orderby,'2'))?"tpaixusel":"tpaixu").'">'.geteqval(array($orderby,1,'时间↓','时间↑')).'</a>';
$tmp_arr['twhereoption'] .= '<a class="thabtn" href="'.getqueurl('wherep',0).'">全部</a><a class="thabtn" href="'.getqueurl('wherep',8).'">激活币</a><a class="thabtn" href="'.getqueurl('wherep',1).'">消费劵</a><a class="thabtn" href="'.getqueurl('wherep',2).'">本金</a><a class="thabtn" href="'.getqueurl('wherep',3).'">团队收益</a><a class="thabtn" href="'.getqueurl('wherep',4).'">利息</a>
	';
	//<a class="thabtn" href="'.getqueurl('wherep',5).'">晋级奖</a><a class="thabtn" href="'.getqueurl('wherep',6).'">积分</a><a class="thabtn" href="'.getqueurl('wherep',7).'">共享积分</a>


$condition=' where 1=1 ';
if($wherep){
	if($wherep==1){
		$condition.=" and typeid=1 ";
	}elseif($wherep==2){
		$condition.=" and typeid=2 ";
	}elseif($wherep==3){
		$condition.=" and typeid=3 ";
	}elseif($wherep==4){
		$condition.=" and typeid=4 ";
	}elseif($wherep==5){
		$condition.=" and typeid=5 ";
	}elseif($wherep==6){
		$condition.=" and typeid=6 ";
	}elseif($wherep==7){
		$condition.=" and typeid=7 ";
	}elseif($wherep==8){
		$condition.=" and typeid=0 ";
	}
}


if($quser){
	$condition.=" and uname like '%".$quser."%'";
}

$order='';
if($orderby==1) $order=' order by transfer_time desc';
if($orderby==2) $order=' order by transfer_time asc';


$tmp_arr['tth']='<th>序号</th><th>会员帐号</th><th>管理员帐号</th><th>操作时间</th><th>类型</th><th>变动金额</th>';

$psql="select count(0) from ld_coin_record $condition";
$db->query($psql,3);
$pcount=$db->fval;
$pagecount=$pagecount;   //每页条数 
$astr="&lsaction=sentencesql&pagecount=$pagecount&orderby=$orderby&option=$option&quser=$quser";	  //Url
$pagearr=pagelist($pagecount,$pcount,$astr);
$offset=$pagearr[1];

$sql="select * from ld_coin_record $condition $order limit $offset,$pagecount";
$db->query($sql);
$ii=0;
foreach ($db->rs as $k => $v) {
	$ii++;
	$serialid=($pagearr[2]-1)*$pagecount+$ii;
	if($v['plus_mius']==1){
		$plus="+";
	}elseif($v['plus_mius']==2){
		$plus="-";
	}
	if($v['typeid']==0){
		$type="激活币";
	}elseif($v['typeid']==1){
		$type="拍单币";
	}elseif($v['typeid']==2){
		$type="本金";
	}elseif($v['typeid']==3){
		$type="团队收益";
	}elseif($v['typeid']==4){
		$type="利息";
	}elseif($v['typeid']==5){
		$type="晋级";
	}elseif($v['typeid']==6){
		$type="积分";
	}elseif($v['typeid']==7){
		$type="共享积分";
	}
	$tmp_arr['ttr'].='<tr class="levelcolor">
						<td><span  title="'.$v["id"].'">'.$serialid.'</span></td>
						<td>'.$v['uname'].'</td>
						<td>'.$v['admin_name'].'</td>
						<td>'.formatdate($v['transfer_time']).'</td>
						<td>'.$type.'</td>
						<td>'.$plus.getfnum($v['coins_number']).'</td>';

	$tmp_arr['ttr'].='</tr>';
}


$tmp_arr['tcount']=$pcount;
$tmp_arr['ttitle']=getmenu($GLOBALARR['menu'],'sentencesql');
$tmp_arr['tpage']=$pagearr[0];
admin_two($tmp_arr);
$db->query("select sum(coins_number) as pamount from ld_coin_record where typeid=2 and plus_mius=1",2);
$plus_amount = $db->rs['pamount'];
$db->query("select sum(coins_number) as mamount from ld_coin_record where typeid=2 and plus_mius=2",2);
$minus_amount = $db->rs['mamount'];
$effect_amount = $plus_amount-$minus_amount;

if($wherep){
	if($wherep==1){
		$condition.=" and typeid=1 ";
	}elseif($wherep==2){
		$condition.=" and typeid=2 ";
	}elseif($wherep==3){
		$condition.=" and typeid=3 ";
	}elseif($wherep==4){
		$condition.=" and typeid=4 ";
	}elseif($wherep==5){
		$condition.=" and typeid=5 ";
	}elseif($wherep==6){
		$condition.=" and typeid=6 ";
	}elseif($wherep==7){
		$condition.=" and typeid=7 ";
	}elseif($wherep==8){
		$condition.=" and typeid=0 ";
	}
}


if($quser){
	$condition.=" and uname like '%".$quser."%'";
}
$sql="select sum(coins_number)as plus from ld_coin_record $condition and plus_mius=1";
$db->query($sql,2);
$plus=$db->rs['plus'];
$sql="select sum(coins_number)as mius from ld_coin_record $condition and plus_mius=2";
$db->query($sql,2);
$mius=$db->rs['mius'];
$tot=$plus-$mius;
echo "<div style='font-size:14px;'><span>增加合计：".$plus."</span></div><div style='font-size:14px;'><span>减少合计：".$mius."</span></div><div style='font-size:14px;'><span>实际增加合计：".$tot."</span></div>";
?>